#include<bits/stdc++.h>
#include<opencv2/opencv.hpp>
#include "func.hpp"

using namespace cv;
using namespace std;
int main(int argc, char *argv[]){     

	if (argc < 3){
		fprintf(stderr, "参数不足\n");
		return -1;
	}

	string input_path;
	string output_path;

	if (!strcmp(argv[2], "encode")){
		input_path = "original picture.png";
		output_path = "encoded picture.png";
	}
	else if (!strcmp(argv[2], "decode")){
		input_path = "encoded picture.png";
		output_path = "decoded picture.png";
	}
	else{
		fprintf(stderr, "参数错误\n");
		return -2;
	}
			  
	Mat input = imread(input_path, IMREAD_UNCHANGED); //读入32位深度的png
	if (input.empty()){
		fprintf(stderr, "%s不存在\n", input_path);
		return -3;
	}

	Mat output = solve(input, argv[1]);
	
	vector<int> compression_params;
	compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
	compression_params.push_back(0);    
	imwrite(output_path, output, compression_params);// 无压缩png.

	return 0;
}